Skip to content

Unit test: WriteBuffer — missing tests for addInt64, addArray, addStringArray, fluent chaining#303

Merged
s2x merged 1 commit intomainfrom
oda-186-unit-test-writebuffer-missing-tests-for
Mar 29, 2026
Merged

Unit test: WriteBuffer — missing tests for addInt64, addArray, addStringArray, fluent chaining#303
s2x merged 1 commit intomainfrom
oda-186-unit-test-writebuffer-missing-tests-for

Conversation

@s2x
Copy link
Copy Markdown
Contributor

@s2x s2x commented Mar 29, 2026

Closes #186

Problem

`WriteBuffer` (159 lines, 15 public methods) has only 14 tests covering basic operations. Missing coverage:

  1. `addInt64(int)` — never tested (signed 64-bit integer)
  2. `addArray(ToStreamBufferInterface ...)` — never tested (serializes array of objects)
  3. `addStringArray(string ...)` — never tested
  4. Fluent chaining — no test verifies that chaining multiple `add*()` calls produces correct output
  5. Boundary values — no tests for max/min values of each integer type
  6. `addUInt32` / `addUInt64` out-of-range — only UInt8 and UInt16 have range validation tests

Expected tests

```php
public function testAddInt64(): void
{
$buf = (new WriteBuffer())->addInt64(-1);
$this->assertSame(str_repeat("\xFF", 8), $buf->getContents());
}

public function testAddInt64MaxValue(): void
{
$buf = (new WriteBuffer())->addInt64(PHP_INT_MAX);
$this->assertSame(pack('J', PHP_INT_MAX), $buf->getContents());
}

public function testAddArray(): void
{
$item1 = new PublishedMessage(0, 'hello');
$item2 = new PublishedMessage(1, 'world');
$buf = (new WriteBuffer())->addArray($item1, $item2);
// Verify: int32 count + item1 binary + item2 binary
}

public function testAddStringArray(): void
{
$buf = (new WriteBuffer())->addStringArray('foo', 'bar');
// Verify: int32 count + string1 + string2
}

public function testFluentChaining(): void
{
$buf = (new WriteBuffer())
->addUInt16(0x0001)
->addUInt16(0x0001)
->addUInt32(1)
->addString('test');
// Verify complete binary output
}

public function testUInt32MaxValue(): void
{
$buf = (new WriteBuffer())->addUInt32(0xFFFFFFFF);
$this->assertSame("\xFF\xFF\xFF\xFF", $buf->getContents());
}
```

Acceptance criteria

  • `addInt64` with positive, negative, zero, min, max values
  • `addArray` with 0, 1, and multiple items
  • `addStringArray` with 0, 1, and multiple strings
  • Fluent chaining produces correct concatenated output
  • Boundary values for all integer types (0, max, min where applicable)

Add 23 new test methods covering:
- addInt64 boundary values (zero, positive, max)
- addArray with 0, 1, and multiple items
- addStringArray with 0, 1, and multiple strings
- Fluent chaining verification
- Boundary values for UInt32, UInt64, Int8
- Out-of-range validation for Int8, Int16, Int32, UInt32

Total: 51 tests, 61 assertions (was 28/31)
@s2x s2x merged commit 1f8a3df into main Mar 29, 2026
7 checks passed
@s2x s2x deleted the oda-186-unit-test-writebuffer-missing-tests-for branch March 29, 2026 20:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unit test: WriteBuffer — missing tests for addInt64, addArray, addStringArray, fluent chaining

1 participant